<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" exclude-result-prefixes="fo">
<xsl:output method="xml" version="1.0" omit-xml-declaration="no" indent="yes"/>

<!-- ========================= -->
<!-- root element: purchaseOrder -->
<!-- ========================= -->

<xsl:template match="purchaseOrder">

	<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <!-- ========================= -->
    <!-- gobal variables           -->
    <!-- ========================= -->
    <xsl:variable name="logoPath" select="images//logo"/>

  	<fo:layout-master-set>
		<fo:simple-page-master master-name="A4-portrait"
        		page-height="11in"
        		page-width="8.5in"
        		margin-top="10mm"
        		margin-bottom="12mm"
      			margin-left="10mm"
      			margin-right="10mm">

            <fo:region-after extent="5mm"/>
			<fo:region-body />
  		</fo:simple-page-master>
	</fo:layout-master-set>


<fo:page-sequence master-reference="A4-portrait">
<!--============================== -->
<!-- Page Number block             -->
<!--============================== -->

<fo:static-content flow-name="xsl-region-after">
	<fo:block font-size="7pt" font-weight="bold" text-align="right">Page <fo:page-number />
	 of <fo:page-number-citation ref-id="endofdoc"/></fo:block>
</fo:static-content>

<fo:flow flow-name="xsl-region-body">

<!--==============================-->
<!-- Logo and Self address block  -->
<!--==============================-->

	<fo:block font-size="8pt" space-after="-5.0mm">
	<fo:table table-layout="fixed" width="100%" >

	<fo:table-column column-width="10mm" />
	<fo:table-column column-width="35mm"/>
	<fo:table-column column-width="10mm" />
	<fo:table-column display-align="center" />
	<fo:table-body>
		<fo:table-row>
			<fo:table-cell />
			<fo:table-cell><fo:external-graphic src="{$logoPath}" content-height = ".4in"  content-width = ".4in" /></fo:table-cell>
			<fo:table-cell />
			<fo:table-cell >
                <fo:block font-size="14pt" font-weight="bold" display-align="center">Purchase Order Receipt Acknowledgement</fo:block>
            </fo:table-cell>
		</fo:table-row>
	</fo:table-body>
	</fo:table >
	</fo:block>

    <fo:block font-size="7pt" space-after="1cm">
	<fo:table table-layout="fixed" width="100%" >
	<fo:table-column display-align="center" />
        <fo:table-body>
            <fo:table-row display-align="center">
                <fo:table-cell display-align="center" >
                    <fo:block font-size="7pt" font-weight="bold" text-align="center"><xsl:value-of select="selfAddress//name" /></fo:block>
                    <fo:block font-size="7pt" font-weight="bold" text-align="center"><xsl:value-of select="selfAddress//address1" /></fo:block>
                    <fo:block font-size="7pt" font-weight="bold" text-align="center"><xsl:value-of select="selfAddress//address2" /></fo:block>
                    <fo:block font-size="7pt" font-weight="bold" text-align="center"><xsl:value-of select="selfAddress//address3" /></fo:block>
                    <fo:block font-size="7pt" font-weight="bold" text-align="center"><xsl:value-of select="selfAddress//address4" /></fo:block>
                    <fo:block font-size="7pt" font-weight="bold" text-align="center"><xsl:value-of select="selfAddress//cityStateZip" /></fo:block>
                    <fo:block font-size="7pt" font-weight="bold" text-align="center"><xsl:value-of select="selfAddress//phoneFax" /></fo:block>
                </fo:table-cell>

            </fo:table-row>
            <fo:table-row  >
                <fo:table-cell />
            </fo:table-row>
        </fo:table-body>
	</fo:table >
	</fo:block>

    <fo:block>
        <fo:table table-layout="fixed" width="100%" >
            <fo:table-column column-width="30mm" />
            <fo:table-body>
                <fo:table-row>
                    <fo:table-cell />
                </fo:table-row>
            </fo:table-body>
        </fo:table>
    </fo:block>

<!-- ================================ -->
<!--   purchaseOrderDetails  -->
<!-- ================================ -->

    <fo:block font-size="8pt" space-after="0.5cm">
	    <xsl:apply-templates select="purchaseOrderDetails"/>
    </fo:block>


<!--=============================== -->
<!-- Line Items details block      -->
<!--=============================== -->

	<fo:block font-size="8pt">
	    <xsl:apply-templates select="lineItems"/>
    </fo:block>

    <fo:table table-layout="fixed" width="100%" space-after="1cm">
        <fo:table-column  column-width="64.55mm"/>
        <fo:table-column  column-width="15.45mm"/>
        <fo:table-body>
            <fo:table-row>
                <fo:table-cell />
                <fo:table-cell>
                    <fo:block font-size="7pt" > <xsl:apply-templates select="total"/> </fo:block>
                     <fo:block font-size="7pt" > <xsl:apply-templates select="freight"/> </fo:block>
                    <fo:block font-size="7pt" > <xsl:apply-templates select="tradeDiscount"/> </fo:block>
                    <fo:block font-size="7pt" > <xsl:apply-templates select="misc"/> </fo:block>
                    <fo:block font-size="7pt" > <xsl:apply-templates select="tax"/> </fo:block>
                    <fo:block font-size="7pt" > <xsl:apply-templates select="orderTotal"/> </fo:block>
                </fo:table-cell>
            </fo:table-row>
        </fo:table-body>
    </fo:table>

    <fo:block id="endofdoc"></fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>

<!-- ================================ -->
<!--  Child element: purchaseOrderDetails  -->
<!-- ================================ -->

<xsl:template match="purchaseOrderDetails">
    <fo:block font-size="7pt">
        <fo:table width="98%" table-layout="fixed">
        <fo:table-column column-width="40mm"/>
        <fo:table-column column-width="40mm"/>
        <fo:table-column column-width="40mm"/>
        <fo:table-column column-width="40mm"/>
        <fo:table-column/>

            <fo:table-body>
            <fo:table-row height="0.6cm" background-color="#DEE1E2">
                <fo:table-cell border="1pt double black" display-align="center" >
                        <fo:block font-weight="bold" text-align="center">Receipt Number</fo:block>
                  </fo:table-cell>
                  <fo:table-cell border="1pt double black" display-align="center" >
                        <fo:block font-weight="bold" text-align="center">PO Number</fo:block>
                  </fo:table-cell>
                  <fo:table-cell border="1pt double black" display-align="center" >
                        <fo:block font-weight="bold" text-align="center">Receipt Date</fo:block>
                  </fo:table-cell>
                  <fo:table-cell border="1pt double black" display-align="center" >
                        <fo:block font-weight="bold" text-align="center">Vendor Name</fo:block>
                  </fo:table-cell>
                <fo:table-cell border="1pt double black" display-align="center" >
                        <fo:block font-weight="bold" text-align="center">Invoice Number</fo:block>
                  </fo:table-cell>
            </fo:table-row>

            <fo:table-row height="0.4cm" background-color="#FFFFEE">
                <fo:table-cell border="1pt double black" display-align="center">
                    <fo:block font-weight="bold" text-align="center">
                    <xsl:value-of select="receiptNumber"/>
                    </fo:block>
                </fo:table-cell>
                <fo:table-cell border="1pt double black" display-align="center" hyphenate="true" language = "en">
                    <fo:block font-weight="bold" text-align="center">
                    <xsl:value-of select="poNumber"/>
                    </fo:block>
                </fo:table-cell>
                <fo:table-cell border="1pt double black" display-align="center" hyphenate="true" language = "en">
                    <fo:block font-weight="bold" text-align="center">
                    <xsl:value-of select="date"/>
                    </fo:block>
                </fo:table-cell>
                <fo:table-cell border="1pt double black" display-align="center" hyphenate="true" language = "en">
                    <fo:block font-weight="bold" text-align="center">
                    <xsl:value-of select="vendorName"/>
                    </fo:block>
                </fo:table-cell>
                <fo:table-cell border="1pt double black" display-align="center" hyphenate="true" language = "en">
                    <fo:block font-weight="bold" text-align="center">
                    <xsl:value-of select="invoiceNumber"/>
                    </fo:block>
                </fo:table-cell>
            </fo:table-row>

        </fo:table-body>
    </fo:table>
    </fo:block>
</xsl:template>

<!-- =================================== -->
 <!--	child element: LineItems	   -->
<!-- =================================== -->

<xsl:template match="lineItems">
	<fo:block font-size="7pt">
        <fo:table width="100%" table-layout="fixed">
		<fo:table-column column-width="11mm"/>
	    <fo:table-column column-width="16mm"/>
	    <fo:table-column column-width="16mm"/>
 		<fo:table-column column-width="21mm"/>
        <fo:table-column column-width="15mm"/>
	    <fo:table-column column-width="15mm"/>
		<fo:table-column column-width="15mm"/>
        <fo:table-column column-width="15mm"/>
		<fo:table-column column-width="15mm" />
        <fo:table-column column-width="25mm"/>
        <fo:table-column column-width="16mm"/>
		<fo:table-column column-width="16mm" />
	        <fo:table-body>
			<fo:table-row height="0.6cm" background-color="#DEE1E2">
				<fo:table-cell border="1pt double black" display-align="center" >
			    		<fo:block font-weight="bold" text-align="center">LineItem</fo:block>
	  			</fo:table-cell>
	  			<fo:table-cell border="1pt double black" display-align="center" >
		    			<fo:block font-weight="bold" text-align="center">Process Name</fo:block>
	  			</fo:table-cell>
	  			<fo:table-cell border="1pt double black" display-align="center" >
		    			<fo:block font-weight="bold" text-align="center">Part Number</fo:block>
	  			</fo:table-cell>
	  			<fo:table-cell border="1pt double black" display-align="center" >
		    			<fo:block font-weight="bold" text-align="center">Description</fo:block>
	  			</fo:table-cell>
	  			<fo:table-cell border="1pt double black" display-align="center" >
		    			<fo:block font-weight="bold" text-align="center">Package Type</fo:block>
	  			</fo:table-cell>
                <fo:table-cell border="1pt double black" display-align="center" >
		    			<fo:block font-weight="bold" text-align="center">Req. Date</fo:block>
	  			</fo:table-cell>
				<fo:table-cell border="1pt double black" display-align="center" >
		    			<fo:block font-weight="bold" text-align="center">Recv. Date</fo:block>
	  			</fo:table-cell>
				<fo:table-cell border="1pt double black" display-align="center" >
					<fo:block font-weight="bold" text-align="center">Req. Qty</fo:block>
				</fo:table-cell>
                <fo:table-cell border="1pt double black" display-align="center" >
					<fo:block font-weight="bold" text-align="center">Recv. Qty</fo:block>
				</fo:table-cell>
                <fo:table-cell border="1pt double black" display-align="center" >
                        <fo:block font-weight="bold" text-align="center">Lot Info</fo:block>
                </fo:table-cell>
                <fo:table-cell border="1pt double black" display-align="center">
                    <fo:block font-weight="bold" text-align="center">Unit Cost($)</fo:block>
                </fo:table-cell>
                <fo:table-cell border="1pt double black" display-align="center">
                    <fo:block font-weight="bold" text-align="center">Ext. Cost($)</fo:block>
                </fo:table-cell>
			</fo:table-row>


			<xsl:for-each select="/purchaseOrder/lineItems/lineItem">
			<fo:table-row height="0.4cm" background-color="#FFFFEE">
				<fo:table-cell border="1pt double black" display-align="center">
					<fo:block font-weight="bold" text-align="center">
					<xsl:value-of select="poLineItem"/>
					</fo:block>
				</fo:table-cell>
				<fo:table-cell border="1pt double black" display-align="center" hyphenate="true" language = "en">
					<fo:block font-weight="bold" text-align="center">
					<xsl:value-of select="ProcessName"/>
					</fo:block>
				</fo:table-cell>
				<fo:table-cell border="1pt double black" display-align="center" hyphenate="true" language = "en">
					<fo:block font-weight="bold" text-align="center">
					<xsl:value-of select="PartNumber"/>
					</fo:block>
				</fo:table-cell>
				<fo:table-cell border="1pt double black" display-align="center" hyphenate="true" language = "en">
					<fo:block font-weight="bold" text-align="center">
					<xsl:value-of select="description"/>
					</fo:block>
				</fo:table-cell>
                <fo:table-cell border="1pt double black" display-align="center" hyphenate="true" language = "en">
					<fo:block font-weight="bold" text-align="center">
					<xsl:value-of select="PakType"/>
					</fo:block>
				</fo:table-cell>
				<fo:table-cell border="1pt double black" display-align="center">
					<fo:block font-weight="bold" text-align="center">
					<xsl:value-of select="requestDate"/>
					</fo:block>
				</fo:table-cell>
                <fo:table-cell border="1pt double black" display-align="center">
					<fo:block font-weight="bold" text-align="center">
					<xsl:value-of select="recvDate"/>
					</fo:block>
				</fo:table-cell>
				<fo:table-cell border="1pt double black" display-align="center">
					<fo:block font-weight="bold" text-align="center">
					<xsl:value-of select="reqQty"/>
					</fo:block>
				</fo:table-cell>
                <fo:table-cell border="1pt double black" display-align="center">
					<fo:block font-weight="bold" text-align="center">
					<xsl:value-of select="recvQty"/>
					</fo:block>
				</fo:table-cell>


                <fo:table-cell border="1pt double black" display-align="center">
                       <fo:table width="100%" table-layout="fixed">
                        <fo:table-column />
                        <fo:table-column />
                        <!--<fo:table-column column-width="6mm"/>-->
                            <fo:table-body>
                                <xsl:for-each select="lotNumbers/lotInfo">
                                    <fo:table-row height="0.4cm" background-color="#FFFFEE">
                                        <fo:table-cell border="1pt double black" display-align="center">
                                            <fo:block font-weight="bold" text-align="center">
                                                <xsl:value-of select="lotNumber"/>
                                            </fo:block>
                                        </fo:table-cell>

                                        <fo:table-cell border="1pt double black" display-align="center">
                                            <fo:block font-weight="bold" text-align="center">
                                                <xsl:value-of select="qtyIn"/>
                                            </fo:block>
                                        </fo:table-cell>
                                        <!--<fo:table-cell border="1pt double black" display-align="center">
                                            <fo:block font-weight="bold" text-align="center">
                                                <xsl:value-of select="qtyOut"/>
                                            </fo:block>
                                        </fo:table-cell>-->

                                    </fo:table-row>
                                </xsl:for-each>
                            </fo:table-body>
                        </fo:table >
                </fo:table-cell>

                <fo:table-cell border="1pt double black" display-align="center">
					<fo:block font-weight="bold" text-align="right">
					<xsl:value-of select="unitPrice"/>
					</fo:block>
				</fo:table-cell>
                <fo:table-cell border="1pt double black" display-align="center">
					<fo:block font-weight="bold" text-align="right">
					<xsl:value-of select="extendedPrice"/>
					</fo:block>
				</fo:table-cell>
			</fo:table-row>
			</xsl:for-each>

		</fo:table-body>
	</fo:table>
	</fo:block>
</xsl:template>

<xsl:template match="total">
    <fo:table margin="0mm" width="100%" table-layout="fixed" background-color="#DEE1E2">
        <fo:table-column column-width="22mm"/>
        <fo:table-column column-width="15.80mm"/>
            <fo:table-body>
            <fo:table-row height="0.3cm">
                <fo:table-cell font-weight="bold"  border="1pt double black" display-align="center">
                    <fo:block font-weight="bold" text-align="right" >Sub Total:$</fo:block>
                </fo:table-cell>
                <fo:table-cell font-weight="bold" border="1pt double black" display-align="center" background-color="#FFFFEE">
                    <fo:block text-align="right"><xsl:value-of select="/purchaseOrder/total"/></fo:block>
                </fo:table-cell>
            </fo:table-row>
        </fo:table-body>
    </fo:table>
</xsl:template>

<xsl:template match="freight">
    <fo:table margin="0mm" width="100%" table-layout="fixed" background-color="#DEE1E2">
        <fo:table-column column-width="22mm"/>
        <fo:table-column column-width="15.80mm"/>
            <fo:table-body>
            <fo:table-row height="0.3cm">
                <fo:table-cell font-weight="bold"  border="1pt double black" display-align="center">
                    <fo:block font-weight="bold" text-align="right" >Freight:$</fo:block>
                </fo:table-cell>
                <fo:table-cell font-weight="bold" border="1pt double black" display-align="center" background-color="#FFFFEE" >
                    <fo:block text-align="right"><xsl:value-of select="/purchaseOrder/freight"/></fo:block>
                </fo:table-cell>
            </fo:table-row>
        </fo:table-body>
    </fo:table>
</xsl:template>

<xsl:template match="tradeDiscount">
    <fo:table margin="0mm" width="100%" table-layout="fixed" background-color="#DEE1E2">
        <fo:table-column column-width="22mm"/>
        <fo:table-column column-width="15.80mm"/>
            <fo:table-body>
            <fo:table-row height="0.3cm">
                <fo:table-cell font-weight="bold"  border="1pt double black" display-align="center">
                    <fo:block font-weight="bold" text-align="right" >TradeDiscount:$</fo:block>
                </fo:table-cell>
                <fo:table-cell font-weight="bold" border="1pt double black" display-align="center" background-color="#FFFFEE" >
                    <fo:block text-align="right"><xsl:value-of select="/purchaseOrder/tradeDiscount"/></fo:block>
                </fo:table-cell>
            </fo:table-row>
        </fo:table-body>
    </fo:table>
</xsl:template>

<xsl:template match="misc">
    <fo:table margin="0mm" width="100%" table-layout="fixed" background-color="#DEE1E2">
        <fo:table-column column-width="22mm"/>
        <fo:table-column column-width="15.80mm"/>
            <fo:table-body>
            <fo:table-row height="0.3cm">
                <fo:table-cell font-weight="bold"  border="1pt double black" display-align="center">
                    <fo:block font-weight="bold" text-align="right" >Miscellaneous:$</fo:block>
                </fo:table-cell>
                <fo:table-cell font-weight="bold" border="1pt double black" display-align="center" background-color="#FFFFEE" >
                    <fo:block text-align="right" ><xsl:value-of select="/purchaseOrder/misc"/></fo:block>
                </fo:table-cell>
            </fo:table-row>
        </fo:table-body>
    </fo:table>
</xsl:template>

<xsl:template match="tax">
    <fo:table margin="0mm" width="100%" table-layout="fixed" background-color="#DEE1E2">
        <fo:table-column column-width="22mm"/>
        <fo:table-column column-width="15.80mm"/>
            <fo:table-body>
            <fo:table-row height="0.3cm">
                <fo:table-cell font-weight="bold"  border="1pt double black" display-align="center">
                    <fo:block font-weight="bold" text-align="right" >Tax:$</fo:block>
                </fo:table-cell>
                <fo:table-cell font-weight="bold" border="1pt double black" display-align="center" background-color="#FFFFEE" >
                    <fo:block text-align="right"><xsl:value-of select="/purchaseOrder/tax"/></fo:block>
                </fo:table-cell>
            </fo:table-row>
        </fo:table-body>
    </fo:table>
</xsl:template>

<xsl:template match="orderTotal">
    <fo:table margin="0mm" width="100%" table-layout="fixed" background-color="#DEE1E2">
        <fo:table-column column-width="22mm"/>
        <fo:table-column column-width="15.80mm"/>
            <fo:table-body>
            <fo:table-row height="0.3cm">
                <fo:table-cell font-weight="bold"  border="1pt double black" display-align="center">
                    <fo:block font-weight="bold" text-align="right" >Order Total:$</fo:block>
                </fo:table-cell>
                <fo:table-cell font-weight="bold" border="1pt double black" display-align="center" background-color="#FFFFEE" >
                    <fo:block text-align="right"><xsl:value-of select="/purchaseOrder/orderTotal"/></fo:block>
                </fo:table-cell>
            </fo:table-row>
        </fo:table-body>
    </fo:table>
</xsl:template>

<!-- =================================== -->
<!--	END of Document		         -->
<!-- =================================== -->

</xsl:stylesheet>